/**
 * 禁止input自动填充
 */
(function () {
    var inputAutoComplete = {};

    /**
     * 监听页面的input和嵌套的iframe
     */
    var target = document.querySelector('body');
    var observer = new MutationObserver(function (mutations) {
        var inputs = $('input');
        $.each(inputs, function (k, v) {
            $(v).attr('autocomplete', 'off');
        });

        var iframes = $('iframe');
        $.each(iframes, function (k, v) {
            var iframeName = !!v.id ? v.id : commonUtil.getUUID();
            v.id = iframeName;
            v.onload = function () {
                setTimeout(function () {
                    inputAutoComplete.onload(iframeName);
                }, 10);
            };
        });
    });
    var config = {
        childList: true
    };
    observer.observe(target, config);


    /**
     * 禁止弹出的iframe中的input自动填充
     */
    inputAutoComplete.onload = function (iframeName) {
        var _iframe = document.getElementById(iframeName);
        if (!!_iframe) {
            var inputs = $(_iframe.contentWindow.document).find('input');
            console.log("iframe中input数量：" + inputs.length);
            $.each(inputs, function (k, v) {
                $(v).attr('autocomplete', 'off');
            });
        } else {
            console.log('Element not found!');
        }
    };

    window.inputAutoComplete = inputAutoComplete
})();